/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package processor;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author maynoigi
 */
public class DateConvert {

    public DateConvert() {
    }

    public static Date dateFrom(Date temp) {
        Calendar form = Calendar.getInstance();
        form.setTime(temp);
        form.set(Calendar.MINUTE, 0);
        form.set(Calendar.SECOND, 0);
        form.set(Calendar.HOUR_OF_DAY, 0);
        Date result = form.getTime();
        return result;
    }

    public static Date dateTo(Date temp) {
        Calendar to = Calendar.getInstance();
        to.setTime(temp);
        to.set(Calendar.MINUTE,59 );
        to.set(Calendar.SECOND, 59);
        to.set(Calendar.HOUR_OF_DAY, 23);
        Date result = to.getTime();
        return result;
    }
        public static String getTimeSolved(Date date1, Date date2) {
        String timeSolved;
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        Calendar cal3 = Calendar.getInstance();
        cal1.setTime(date1);
        cal2.setTime(date2);
        long span = cal2.getTimeInMillis() - cal1.getTimeInMillis();
        cal3.setTimeInMillis(span);
        long numberOfMSInADay = 1000 * 60 * 60 * 24;
        timeSolved = String.valueOf(cal3.getTimeInMillis() / numberOfMSInADay);
        return timeSolved;
    }
}
